﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using WeifenLuo.WinFormsUI.Docking;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Oracle;
using System.Data.Common;

namespace GgCarControl
{
    public partial class ModifySendCard : DockContent
    {
        public ModifySendCard()
        {
            InitializeComponent();
        }

        public static Database db =
             new OracleDatabase("Data Source=DG;User ID=dgrfid;Password=dgrfid;Unicode=True;Load Balance Timeout=1000");
        DataTable dt;

        private void ModifySendCard_Load(object sender, EventArgs e)
        {
            this.textBox_card_no.Focus();
        }

        private void textBox_card_no_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)13)
            {
                this.textBox_car_no.Focus();
            }
        }

        private void textBox_card_no_Leave(object sender, EventArgs e)
        {
            string card_no = this.textBox_card_no.Text.ToString().Trim();
            if (card_no.Length > 0)
            {
                string get_car = "select XLH,CARDID,CHEHAO,CARDSTATE from RFID_READ where XLH='" + card_no + "'";
                dt = db.ExecuteDataSet(db.GetSqlStringCommand(get_car.ToString())).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    string car_no = dt.Rows[0]["CHEHAO"].ToString().Trim();
                    this.textBox_car_no.Text = car_no;
                }
                else
                {
                    this.textBox_card_no.Text = "";
                    MessageBox.Show("输入的序列号有误，请重新输入!");
                }
            }
        }

        private void button_modify_Click(object sender, EventArgs e)
        {
            string card_no = this.textBox_card_no.Text.ToString();
            string car_no = this.textBox_car_no.Text.ToString().ToUpper();
            string update_rfid_read = "update RFID_READ set CHEHAO='" + car_no + "' where XLH='" + card_no + "'";
            db.ExecuteNonQuery(db.GetSqlStringCommand(update_rfid_read.ToString()));
            MessageBox.Show("车、卡关联修改成功!");
        }
    }
}
